<%@ page contentType="image/jpeg" import="java.awt.*, java.awt.image.*, java.util.*, javax.imageio.*"%>
<%
out.clear();
System.setProperty("java.awt.headless", "true");
String name=request.getParameter("name");
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

int width=160, height=50;
int r, g, b;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics gi = image.getGraphics();
Random random = new Random();

r=200 + random.nextInt(30);
g=200 + random.nextInt(30);
b=200 + random.nextInt(30);

gi.setColor(new Color(r, g, b));
gi.fillRect(0, 0, width, height);

gi.setFont(new Font("Times New Roman", Font.BOLD, 40));

r=160 + random.nextInt(40);
g=160 + random.nextInt(40);
b=160 + random.nextInt(40);

gi.setColor(new Color(r, g, b));

for (int i = 0; i < 155; i++){
	int x = random.nextInt(width);
	int y = random.nextInt(height);
	int xl = random.nextInt(13);
	int yl = random.nextInt(13);
	gi.drawLine(x, y, x+xl, y+yl);
}
final String [] words = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", 
        "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", 
        "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", 
        "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
        "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
        "y", "z", "0", "1", "2", "3", "4", "5", "6", "7",
        "8", "9"};
String sRand="";
for (int i = 0; i < 5; i++){
	String rand=String.valueOf(words[random.nextInt(62)]);
    sRand += rand;
   	gi.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
    gi.drawString(rand, 30*i + 6, 40);
}

session.setAttribute(name, sRand);
gi.dispose();

ImageIO.write(image, "JPEG", response.getOutputStream());
%>